<ix-modal-header [requiredRoles]="requiredRoles" [title]="title" [loading]="isLoading()"></ix-modal-header>

<mat-card>
  <mat-card-content>
    <form class="ix-form-container" [formGroup]="form" (submit)="onSubmit()">
      <div class="fieldsets">
        <ix-fieldset class="fieldset" [title]="'Source' | translate">
          <ix-explorer
            formControlName="path"
            [label]="'Path' | translate"
            [tooltip]="helptext.rsyncPathTooltip | translate"
            [required]="true"
            [nodeProvider]="treeNodeProvider"
          ></ix-explorer>

          <ix-combobox
            formControlName="user"
            [label]="'User' | translate"
            [tooltip]="helptext.rsyncUserTooltip | translate"
            [required]="true"
            [provider]="userProvider"
          ></ix-combobox>

          <ix-select
            formControlName="direction"
            [label]="'Direction' | translate"
            [tooltip]="helptext.rsyncDirectionTooltip | translate"
            [required]="true"
            [options]="directions$"
          ></ix-select>

          <ix-input
            formControlName="desc"
            [label]="'Description' | translate"
          ></ix-input>
        </ix-fieldset>

        <ix-fieldset class="fieldset" [title]="'Remote' | translate">
          <ix-select
            formControlName="mode"
            [label]="'Rsync Mode' | translate"
            [tooltip]="helptext.rsyncModeTooltip | translate"
            [options]="rsyncModes$"
            [hideEmpty]="true"
          ></ix-select>

          @if (isModuleMode) {
            <ix-input
              formControlName="remotehost"
              [label]="'Remote Host' | translate"
              [required]="true"
              [tooltip]="helptext.rsyncRemotehostTooltip | translate"
            ></ix-input>
            <ix-input
              formControlName="remotemodule"
              [label]="'Remote Module Name' | translate"
              [tooltip]="helptext.rsyncRemotemoduleTooltip | translate"
              [required]="true"
            ></ix-input>
          } @else {
            <ix-select
              formControlName="sshconnectmode"
              [label]="'Connect using:' | translate"
              [tooltip]="helptext.rsyncSshConnectModeTooltip | translate"
              [options]="sshConnectModes$"
              [hideEmpty]="true"
            ></ix-select>

            @if (isSshConnectionPrivateMode) {
              <ix-input
                formControlName="remotehost"
                [label]="'Remote Host' | translate"
                [required]="true"
                [tooltip]="helptext.rsyncRemotehostTooltip | translate"
              ></ix-input>
              @if (isRemoteHostSpecified) {
                <ix-slide-toggle
                  formControlName="ssh_keyscan"
                  [label]="'SSH Keyscan' | translate"
                  [tooltip]="helptext.sshKeyscanTooltip | translate"
                ></ix-slide-toggle>
              }
              <ix-input
                formControlName="remoteport"
                type="number"
                [label]="'Remote SSH Port' | translate"
                [required]="true"
                [tooltip]="helptext.rsyncRemoteportTooltip | translate"
              ></ix-input>
            } @else {
              <ix-ssh-credentials-select
                formControlName="ssh_credentials"
                [label]="'SSH Connection' | translate"
                [tooltip]="helptext.rsyncSshCredentialsTooltip | translate"
                [required]="true"
              ></ix-ssh-credentials-select>
            }

            <ix-input
              formControlName="remotepath"
              [label]="'Remote Path' | translate"
            ></ix-input>
            <ix-checkbox
              formControlName="validate_rpath"
              [label]="'Validate Remote Path' | translate"
              [tooltip]="helptext.rsyncValidateRpathTooltip | translate"
            ></ix-checkbox>
          }

        </ix-fieldset>

        <ix-fieldset class="fieldset" [title]="'Schedule' | translate">
          <ix-scheduler
            formControlName="schedule"
            [required]="true"
            [label]="'Schedule' | translate"
            [tooltip]="helptext.rsyncPickerTooltip | translate"
          ></ix-scheduler>

          <ix-checkbox
            formControlName="recursive"
            [label]="'Recursive' | translate"
            [tooltip]="helptext.rsyncRecursiveTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="enabled"
            [label]="'Enabled' | translate"
          ></ix-checkbox>
        </ix-fieldset>

        <ix-fieldset class="fieldset" [title]="'More Options' | translate">
          <ix-checkbox
            formControlName="times"
            [label]="'Times' | translate"
            [tooltip]="helptext.rsyncTimesTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="compress"
            [label]="'Compress' | translate"
            [tooltip]="helptext.rsyncCompressTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="archive"
            [label]="'Archive' | translate"
            [tooltip]="helptext.rsyncArchiveTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="delete"
            [label]="'Delete' | translate"
            [tooltip]="helptext.rsyncDeleteTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="quiet"
            [label]="'Quiet' | translate"
            [tooltip]="helptext.rsyncQuietTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="preserveperm"
            [label]="'Preserve Permissions' | translate"
            [tooltip]="helptext.rsyncPreservepermTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="preserveattr"
            [label]="'Preserve Extended Attributes' | translate"
            [tooltip]="helptext.rsyncPreserveattrTooltip | translate"
          ></ix-checkbox>

          <ix-checkbox
            formControlName="delayupdates"
            [label]="'Delay Updates' | translate"
            [tooltip]="helptext.rsyncDelayupdatesTooltip | translate"
          ></ix-checkbox>

          <ix-chips
            formControlName="extra"
            [label]="'Auxiliary Parameters' | translate"
            [tooltip]="helptext.rsyncExtraTooltip | translate"
          ></ix-chips>
        </ix-fieldset>
      </div>

      <div class="form-actions">
        <button
          *ixRequiresRoles="requiredRoles"
          mat-button
          type="submit"
          color="primary"
          ixTest="save"
          [disabled]="form.invalid || isLoading()"
        >
          {{ 'Save' | translate }}
        </button>
      </div>
    </form>
  </mat-card-content>
</mat-card>
